// pages/verify/verify.js
//获取应用实例
let {EditPhone}=require("../../api/api");
Page({
  /**
   * 页面的初始数据
   */
  data: {
    tel: "",
    showHint: false,
  },
  //手机号的双向数据绑定
  telValue(e) {
    this.setData({
      tel: e.detail.value
    })
  },

  //点击确认提交数据
  affirm() {
    // 电话和验证码不为空时
    let { tel } = this.data;
    let RegExp = /^1[3|4|5|8][0-9]\d{8}$/.test(tel);
    if (RegExp) {
      let openid = wx.getStorageSync('openid');
      EditPhone(openid,tel,(e)=>{
        wx.setStorageSync("authorization", "1");
        wx.reLaunch({
          url: '../index/index',
        })
      });
      this.setData({
        showHint: false
      });
    } else {
      this.setData({
        showHint: true
      });
    }

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let tel = options.phone;
    if (tel) {
      this.setData({
        tel
      })
    }
  },

})